<?php defined('BASEPATH') || exit('No direct script access allowed');

/**
 * Building controller
 */
class Banner extends Api_Controller
{
    /**
     * @apiDefine banner 轮播图
     */
    function __construct()
    {
        // Construct the parent class
        parent::__construct();
        $this->load->model('banner_m');
    }

    /**
     * @api               {get} banner/index 轮播图
     * @apiGroup          banner
     * @apiName           banner/index
     * @apiVersion        1.0.0
     * @apiDescription    车型列表
     * @apiSampleRequest https://api.bjxpel.cn/api/banner/index
     * @apiParam {Int} type 案例轮播传0，视频轮播传1 默认0
     * @apiSuccess {String} pic_url 轮播图链接
     * @apiSuccess {String} link 跳转链接
     * @apiSuccessExample 成功响应
     *          {
     *           "message": "ok",
     *           "code": 200,
     *           "data": null
     *          }
     * @apiErrorExample   失败响应
     *            {
     *             "message": "err",
     *             "code": 0,
     *             "data": null
     *            }
     */
    public function index()
    {
        $type   = $this->input->get('type') ?? 0;
        $banner = $this->banner_m->select(['type' => $type]);
        if (!$banner) {
            return $this->failure();
        }
        foreach ($banner as $key => $value) {
            if ($value['type'] == 0) {
                $banner[$key]['type_name'] = "案例轮播";
            } else {
                $banner[$key]['type_name'] = "视频轮播";
            }
        }
        return $this->success(['list' => $banner]);
    }

}